package com.alibaba.nacos.api.remote.request;

import com.alibaba.nacos.api.remote.Payload;
import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

public abstract class Request
        implements Payload {
    @Getter
    private final Map<String, String> headers = new TreeMap<>();
    @Getter
    @Setter
    private String requestId;

    public void putHeader(String key,
                          String value) {
        headers.put(key, value);
    }

    public void putAllHeaders(Map<String, String> headers) {
        this.headers.putAll(Optional.ofNullable(headers).orElse(Collections.emptyMap()));
    }

    public String getHeader(String key) {
        return headers.get(key);
    }

    public String getHeader(String key,
                            String defaultValue) {
        return Optional.ofNullable(headers.get(key)).orElse(defaultValue);
    }

    public void clearHeaders() {
        this.headers.clear();
    }

    public abstract String getModule();
}
